package com.app.masker;

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;

import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import android.view.View;
import android.widget.Toast;

import com.app.masker.ui.main.SectionsPagerAdapter;
import com.zndroid.masker.GuiderMasker;
import com.zndroid.masker.animation.IMaskerClickedListener;
import com.zndroid.masker.shape.Focus;
import com.zndroid.masker.shape.FocusGravity;

public class TabMainActivity extends AppCompatActivity implements IMaskerClickedListener {
    TabLayout tabs;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_main);
        SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
        ViewPager viewPager = findViewById(R.id.view_pager);
        viewPager.setAdapter(sectionsPagerAdapter);
        tabs = findViewById(R.id.tabs);
        tabs.setupWithViewPager(viewPager);
        FloatingActionButton fab = findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        showIntro(tabs.getTabAt(0).view, "tab0", "this is tab test", FocusGravity.LEFT);
    }

    public void showIntro(View view, String id, String text, FocusGravity focusGravity) {
        new GuiderMasker.Builder(TabMainActivity.this)
                .enableDotAnimation(true)
                .setFocusGravity(focusGravity)
                .setFocusType(Focus.MINIMUM)
                .setDelayMillis(100)
                .enableFadeAnimation(true)
                .performClick(true)
                .setInfoText(text)
                .setTarget(view)
                .setListener(this)
                .setUsageId(id)
                .show();
    }

    @Override
    public void onUserClicked(String maskerIntroViewId) {
        if (maskerIntroViewId.equalsIgnoreCase("tab0"))
            showIntro(tabs.getTabAt(1).view, "tab1", "this is tab test", FocusGravity.RIGHT);
        if (maskerIntroViewId.equalsIgnoreCase("tab1"))
            showIntro(tabs.getTabAt(2).view, "tab2", "this is tab test", FocusGravity.RIGHT);
        if (maskerIntroViewId.equalsIgnoreCase("tab2"))
            showIntro(tabs.getTabAt(3).view, "tab3", "this is tab test", FocusGravity.RIGHT);
        if (maskerIntroViewId.equalsIgnoreCase("tab3"))
            Toast.makeText(TabMainActivity.this, "tab Complete!", Toast.LENGTH_SHORT).show();
    }
}